package com.cwl.pattern.单例模式;

/**
 * @program: simple_tools
 * @description: 单例模式-懒汉式
 * @author: ChenWenLong
 * @create: 2019-06-21 17:48
 **/
public class LazySingleton {
    //保证 instance 在所有线程中同步
    private static volatile LazySingleton instance=null;
    //避免类在外部被实例化
    private LazySingleton(){}

    public static synchronized LazySingleton getInstance() {
        //getInstance 方法前加同步
        if(instance==null) {
            instance=new LazySingleton();
        }
        return instance;
    }
}
